namespace PortalWeb.CMS.Dao.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class EWebSystem : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Articles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ModelID = c.Int(nullable: false),
                        Author = c.String(maxLength: 50),
                        Intro = c.String(maxLength: 255),
                        Source = c.String(maxLength: 50),
                        Content = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.CommonModels", t => t.ModelID, cascadeDelete: true)
                .Index(t => t.ModelID);
            
            CreateTable(
                "dbo.CommonModels",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DefaultPicUrl = c.String(),
                        Hits = c.Int(nullable: false),
                        Inputer = c.String(),
                        Model = c.String(),
                        ReleaseDate = c.DateTime(nullable: false),
                        Status = c.Int(nullable: false),
                        Title = c.String(nullable: false, maxLength: 255),
                        CategoryId = c.Int(nullable: false),
                        Consultation_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Categories", t => t.CategoryId, cascadeDelete: true)
                .ForeignKey("dbo.Consultations", t => t.Consultation_Id)
                .Index(t => t.CategoryId)
                .Index(t => t.Consultation_Id);
            
            CreateTable(
                "dbo.Attachments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ModelId = c.Int(),
                        Extension = c.String(),
                        FileParth = c.String(),
                        Owner = c.String(),
                        UploadDate = c.DateTime(nullable: false),
                        Type = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.CommonModels", t => t.ModelId)
                .Index(t => t.ModelId);
            
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ParentId = c.Int(nullable: false),
                        CategoryView = c.String(maxLength: 255),
                        ContentView = c.String(maxLength: 255),
                        Description = c.String(),
                        LinkUrl = c.String(maxLength: 255),
                        MetaDescription = c.String(),
                        MetaKeywords = c.String(),
                        Model = c.String(maxLength: 50),
                        Name = c.String(nullable: false, maxLength: 50),
                        Order = c.Int(nullable: false),
                        PageSize = c.Int(nullable: false),
                        ParentPath = c.String(nullable: false),
                        RecordName = c.String(maxLength: 255),
                        RecordUnit = c.String(maxLength: 255),
                        Type = c.Int(nullable: false),
                        ContentOrder = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Consultations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        QQ = c.String(maxLength: 16),
                        Email = c.String(),
                        Content = c.String(nullable: false, maxLength: 1000),
                        IsPublic = c.Boolean(nullable: false),
                        ReplyContent = c.String(),
                        ReplyTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Comments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ModelId = c.Int(nullable: false),
                        Title = c.String(maxLength: 255),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Jobs",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Products",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ModelID = c.Int(nullable: false),
                        Brand = c.String(maxLength: 255),
                        Size = c.String(maxLength: 255),
                        Price = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Intro = c.String(maxLength: 255),
                        Content = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.CommonModels", t => t.ModelID, cascadeDelete: true)
                .Index(t => t.ModelID);
            
            CreateTable(
                "dbo.SiteInfoes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                        Title = c.String(nullable: false, maxLength: 50),
                        Url = c.String(nullable: false, maxLength: 50),
                        LogoUrl = c.String(maxLength: 255),
                        MetaDescription = c.String(nullable: false, maxLength: 500),
                        MetaKeywords = c.String(nullable: false, maxLength: 500),
                        Copyright = c.String(nullable: false, maxLength: 500),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Products", "ModelID", "dbo.CommonModels");
            DropForeignKey("dbo.Articles", "ModelID", "dbo.CommonModels");
            DropForeignKey("dbo.CommonModels", "Consultation_Id", "dbo.Consultations");
            DropForeignKey("dbo.CommonModels", "CategoryId", "dbo.Categories");
            DropForeignKey("dbo.Attachments", "ModelId", "dbo.CommonModels");
            DropIndex("dbo.Products", new[] { "ModelID" });
            DropIndex("dbo.Attachments", new[] { "ModelId" });
            DropIndex("dbo.CommonModels", new[] { "Consultation_Id" });
            DropIndex("dbo.CommonModels", new[] { "CategoryId" });
            DropIndex("dbo.Articles", new[] { "ModelID" });
            DropTable("dbo.SiteInfoes");
            DropTable("dbo.Products");
            DropTable("dbo.Jobs");
            DropTable("dbo.Comments");
            DropTable("dbo.Consultations");
            DropTable("dbo.Categories");
            DropTable("dbo.Attachments");
            DropTable("dbo.CommonModels");
            DropTable("dbo.Articles");
        }
    }
}
